import {request} from "../../request/index.js"

const app = getApp()

Page({
  data: {
    show:false,//控制下拉列表的显示隐藏，false隐藏、true显示
    selectData:['准备抢修', '开始检修', '结束检修', '开始供电'],//下拉列表的数据
    index:0,
    updateList: [],
    line1: '',
    line2: '',
    line3: '',
    text: '',
    text2: '',
    text3: ''
  },
  onLoad(options){
    console.log(options)
    var updateList = JSON.parse(options.updateList)
    this.setData({
      updateList,
      line1: options.line1,
      line2: options.line2,
      line3: options.line3,
      text: options.text,
      text2: options.text2,
      text3: options.text3
    })
  },
  // 点击下拉显示框
  selectTap(){
    this.setData({
     show: !this.data.show
    });
  },
  // 点击下拉列表
  optionTap(e){
    let Index=e.currentTarget.dataset.index;//获取点击的下拉列表的下标
    this.setData({
      index:Index,
      show:!this.data.show
    })
  },
  gotoUpdateProgressPage(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/updateProgressPage/updateProgressPage?id=' + id + '&text=' + this.data.text + '&text2=' + this.data.text2 + '&text3=' + this.data.text3 + '&line1=' + this.data.line1 + '&line2=' + this.data.line2 + '&line3=' + this.data.line3
    })
  },
  getLocation(e) {
    console.log(app.userId)
    console.log(e.currentTarget.dataset.id)
    wx.getLocation({
      type: 'gcj02',
      success (res) {     
        request({
          url: '/api/upload/location',
          method: 'POST',
          data: {
            planId: e.currentTarget.dataset.id,
            userId: app.userId,
            lon: res.longitude,
            lat: res.latitude 
          }
        })
        .then(res => {
          console.log(res)
          if(res.data.code === 200) {
            wx.showToast({
              title: '上传位置成功', 
              icon: 'none',
              mask: true
            })
          } else {
            wx.showToast({
              title: '上传位置失败',
              icon: 'none',
              mask: true
            })
          }
        })
      }
    })
  }
})